package com.goods.controller.business;

import com.goods.business.service.OutStockService;
import com.goods.common.model.business.OutStock;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.OutStockVO;
import com.goods.common.vo.system.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/business/outStock")
public class OutStockController {

    @Autowired
    private OutStockService outStockService;

    /**
     * 出库单列表
     */
    @GetMapping("/findOutStockList")
    public ResponseBean findOutStockList(@RequestParam("pageNum")int pageNum,
                                         @RequestParam("pageSize")int pageSize,
                                         @RequestParam("status")Integer status){
        try {
            PageVO<OutStockVO> pageVO = outStockService.findOutStockList(pageNum,pageSize,status);
            return ResponseBean.success(pageVO);
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseBean.error("查询失败");
        }
    }


    /**
     * 添加出库单
     * @return
     */
    @PostMapping("/addOutStock")
    public ResponseBean addOutStock(@RequestBody OutStockVO outStockVO){
        try {
            outStockService.addOutStock(outStockVO);
            return ResponseBean.success();
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseBean.error("添加失败失败");
        }
    }


    /**
     * 审核
     * @param id
     * @return
     */
    @PutMapping("/publish/{id}")
    public ResponseBean publish(@PathVariable Long id){
        outStockService.publish(id);
        return ResponseBean.success();
    }
}
